import axios from 'axios';
import qs from 'qs'

let http = {get: "", post: ""}


http.post = (url, data) => {
    return new Promise((resolve, reject) => {
        const token = sessionStorage.getItem("token");
        if(token){
            axios.defaults.headers.common['token'] = token;
            axios.defaults.headers.common['Authorization'] = token;
        }
        const options = {
            method: 'POST',
            headers: { 'content-type': 'application/json' },
            data: data,
            url,
        };
        axios(options).then(res => {
            resolve(res.data)

        });

    })
}


http.get = (url, data) => {
    let params = qs.stringify(data)
    return new Promise((resolve, reject) => {
        axios.get(url, params).then((res) => {
            resolve(res)
        })
    })
}


export default http
